package com.jianganming.singleton;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 * 破坏单例方式一：反序列化
 */
public class Deserialize {
    public static void main(String[] args)throws Exception {
        Singleton singleton = Singleton.getInstance();
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("/Users/jianganming/singleton.txt"));
        oos.writeObject(singleton);
        oos.flush();
        oos.close();

        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("/Users/jianganming/singleton.txt"));
        Object o = ois.readObject();
        System.out.println(singleton);
        System.out.println(o);
        ois.close();
    }
}
